{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入模拟次数:1000\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import scipy as sp\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "\n",
    "n = int(input('请输入模拟次数:'))\n",
    "distance = np.zeros(n)\n",
    "step = np.random.randint(2,size=n)\n",
    "z = np.zeros(n)\n",
    "\n",
    "for i in range(1, n):\n",
    "\tif step[i] == 1:\n",
    "\t    distance[i] = distance[i-1] + step[i]\n",
    "\telse:\n",
    "\t\tdistance[i] = distance[i-1] - 1\n",
    "\tz[i] = np.sqrt(i)\n",
    "dis = np.sqrt(distance**2)\n",
    "x = np.linspace(1, n, n)\n",
    "plt.plot(x, dis, x, z)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
